﻿
using System.Configuration;
using System;
using System.Collections.Generic;
using ASPControlsExtended.Demo.Models;
using System.Xml;
using System.IO;

namespace ASPControlsExtended.Demo.Services {
    public sealed class ListService : IDisposable {

        private List<ProductInfo> _products = null;

        public ListService() {

        }

        public List<ProductInfo> GetList() {
            if (_products != null) {
                return _products;
            }

            _products = new List<ProductInfo>() {
                new ProductInfo() {Product ="Alice Mutton", Category="Meat/Poultry", Quantity="20 - 1 kg tins"},		
                new ProductInfo() {Product ="Aniseed Syrup", Category="Condiments", Quantity="12 - 550 ml bottles"},		
                new ProductInfo() {Product ="Boston Crab Meat", Category="Seafood", Quantity="24 - 4 oz tins"},		
                new ProductInfo() {Product ="Camembert Pierrot", Category="Dairy Products", Quantity="15 - 300 g rounds"},		
                new ProductInfo() {Product ="Carnarvon Tigers", Category="Seafood", Quantity="16 kg pkg."},		
                new ProductInfo() {Product ="Chai", Category="Beverages", Quantity="10 boxes x 20 bags"},		
                new ProductInfo() {Product ="Chang", Category="Beverages", Quantity="24 - 12 oz bottles"},		
                new ProductInfo() {Product ="Chartreuse verte", Category="Beverages", Quantity="750 cc per bottle"},		
                new ProductInfo() {Product ="Chef Anton's Cajun Seasoning", Category="Condiments", Quantity="48 - 6 oz jars"},		
                new ProductInfo() {Product ="Chef Anton's Gumbo Mix", Category="Condiments", Quantity="36 boxes"},		
                new ProductInfo() {Product ="Chocolade", Category="Confections", Quantity="10 pkgs."},		
                new ProductInfo() {Product ="Côte de Blaye", Category="Beverages", Quantity="12 - 75 cl bottles"},		
            };

            return _products;
        }

        #region IDisposable Members

        private bool _isDisposed = false;

        ~ListService() {
            Dispose(false);
        }

        public void Dispose() {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool canDisposeManagedResources) {
            if (_isDisposed) {
                return;
            }

            try {
                DisposeUnmanagedResources();
            }
            catch (Exception ex) {

            }

            _isDisposed = true;
        }

        private void DisposeUnmanagedResources() {

            if (_products != null) {
                _products.Clear();
                _products = null;
            }
        }

        /// <summary>
        /// This should be the first statement in all public members of this object.
        /// </summary>
        private void CheckIfDisposeAndRaiseException() {
            if (_isDisposed)
                throw new ObjectDisposedException(this.GetType().FullName);

        }

        #endregion

    }
}